<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script type="text/javascript" src="/plug-in/jquery-easyui-1.5.1/datagrid-detailview.js"></script>
<title>合同统计</title>
<script>
	$(function(){
		p.className = "com.fs.jzzn.pojo.Contract";
		/*列表初始化*/
		var gridParam = {
			url : '/console/com.fs.jzzn.pojo.Contract/list',
			queryParams:{
				rightControl: true //启用数据权限控制
			},
			columns : [[ 
				{field: 'outContractNo', title: '内部合同编号', width: 130}
				,{field: 'contractNo', title: '订单编号', width: 270}
				,{field: 'contractTitle', title: '订单名称', width: 250}
				,{field: 'contractType', title: '合同类型', width: 80}
				,{field: 'contractLevel', title: '合同级别', width: 100}
				,{field: 'contractName', title: '合同名称', width: 250}
				,{field: 'signDate', title: '签订日期', width: 120}
				,{field: 'partA', title: '合同甲方', width: 250}
				,{field: 'partB', title: '合同乙方', width: 250}
				,{field: 'partAuser', title: '甲方经办人', width: 120}
				,{field: 'partAphone', title: '甲方联系电话', width: 120}
				,{field: 'partBuser', title: '乙方经办人', width: 120}
				,{field: 'partBphone', title: '乙方联系电话', width: 120}
				,{field: 'budgetMoney', title: '预算金额', width: 90}
				,{field: 'actualMoney', title: '实际金额', width: 90}
				,{field: 'billMoney', title: '开票金额', width: 90}
				,{field: 'auditMoney', title: '审计金额', width: 90}
				,{field: 'returnedMoney', title: '回款金额', width: 90}
				,{field: 'payDesc', title: '付款情况及说明', width: 130}
				,{field: 'mainUnit', title: '总包单位', width: 180}
				,{field: 'assistUnit', title: '分包单位', width: 180}
				,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
					return (value || '') + '-' + (row.orgNoName|| '') ;
				}}
				,{field : 'remark',width : 150,title: '备注'}
				,{field: 'createTime', title: '创建时间', width: 180}
				,{field: 'createrName', title: '创建人', width: 180}
			] ],
			singleSelect : true,
			onLoadSuccess: function(){
				p.tooltip(['contractNo' ,  'contractTitle' , 'outContractNo' , 'contractName' ,'partA' ,'partB' ,'partAuser' ,'payDesc' ]);
			},
			view: detailview,
			detailFormatter:function(index,row){
				return '<div class="details" style="padding:5px 0;min-height:200px;"></div>';
			},
			onExpandRow:function(index,row){
				var contractNo = row.contractNo || '';
				if(contractNo=='') return ;
				var ddv = $(this).datagrid('getRowDetail',index).find('div.details');
				var detailGrid = ddv.datagrid({
					url : '/console/com.fs.jzzn.pojo.Project/list',
					queryParams: {
						contractNo: row.contractNo,
						contractNo_searchType: "eq"
					},
					title:'子单项工程列表-'+ row.contractNo,
					pageSize:30,
					rownumbers: true,
					pagination: true,
					singleSelect: true, 
					columns : [[
						{field: 'pNo', title: '工程路段编号', width: 130} 
						,{field: 'pRoad', title: '工程段落', width: 270}
						,{field: 'status', title: '项目状态', width: 120}
						,{field: 'pType', title: '专业类别', width: 80}
						,{field: 'contractNo', title: '订单编号', width: 240}
						,{field: 'pName', title: '项目名称', width: 250}
						,{field: 'budgetMoney', title: '立项预算', width: 90}
						,{field: 'actualMoney', title: '完工预算', width: 90}
						,{field: 'designLength', title: '设计长度', width: 80}
						,{field: 'pm', title: '项目经理', width: 100}
						,{field: 'marketManager', title: '市场负责人', width: 100}
						,{field: 'constructionUnit', title: '建设单位', width: 200}
						,{field: 'designUnit', title: '设计单位', width: 120}
						,{field: 'operator', title: '运营商', width: 120}
						,{field: 'ppm', title: '工程经理', width: 120}
						,{field: 'orgNo', title: '所属机构', width: 180,formatter: function(value,row,index){
							return (value || '') + '-' + (row.orgNoName|| '') ;
						}}
						,{field: 'pCreateDate', title: '订单日期', width: 120}
						,{field: 'subpackage', title: '是否分包', width: 120}
						,{field: 'subpackageScale', title: '分包比例', width: 120}
						,{field: 'region', title: '区域', width: 120}
						,{field: 'priority', title: '优先级', width: 120}
						,{field : 'remark',width : 150,title: '备注'}
						,{field: 'createTime', title: '创建时间', width: 130}
						,{field: 'createrName', title: '创建人', width: 120}
					]],
					onLoadSuccess:function(){
						p.tooltip(['pRoad','contractNo','pName']);
						$('#dataGrid').datagrid('fixDetailRowHeight',index);
						var dData = detailGrid.datagrid('getData');
						var total = {budgetMoney:0,actualMoney:0,designLength: 0,pName:'合计：'};
						$.each(dData.rows ||[], function (i,item) {
							total.budgetMoney += parseFloat(item.budgetMoney || '0');
							total.actualMoney += parseFloat(item.actualMoney || '0');
							total.designLength += parseFloat(item.designLength || '0');
						});
						total.budgetMoney = total.budgetMoney.toFixed(2);
						total.actualMoney = total.actualMoney.toFixed(2);
						total.designLength = total.designLength.toFixed(2);
						detailGrid.datagrid('appendRow',total);
					},
					toolbar: [
				          { iconCls: 'icon-excel', text:'订单子单项工程导出',handler: function(){
					        	  p.down({
					        		  filename: row.contractTitle,local :true,grid:detailGrid,
					        		  url:'/console/project/export' ,
					        	 });
				          }}
					]
				});
			}
		};
		p.dataGrid = $(p.dataGrid).datagrid( $.extend({}, p.dataGridParam, gridParam));

		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var id = $(this).attr("motion_code");
			switch (id) {
				case "05":
					p.gridQuery();
					break;
				case "15":
					var _parent = parent;
					var row = p.getSelection();
					if(row){
						if(_parent.consoleFn){
							var url = '/console/statistics/rewrite/incomeconfig?contractNo='+ row.contractNo;
							_parent.consoleFn.addTab('合同收入统计',0,url,null);
						}
					}
					break;
				case "16":
					var _parent = parent;
					var row = p.getSelection();
					if(row){
						if(_parent.consoleFn){
							var url = '/console/statistics/rewrite/expenseconfig?contractNo='+ row.contractNo;
							_parent.consoleFn.addTab('合同支出统计',1,url,null);
						}
					}
					break;
				case "17":
					var _parent = parent;
					var row = p.getSelection();
					if(row){
						if(_parent.consoleFn){
							var url = '/console/statistics/rewrite/invoiceconfig?contractNo='+ row.contractNo;
							_parent.consoleFn.addTab('合同发票统计',2,url,null);
						}
					}
					break;
				case "18":
					var _parent = parent;
					var row = p.getSelection();
					if(row){
						if(_parent.consoleFn){
							var url = '/console/statistics/rewrite/contractconfig?contractNo='+ row.contractNo;
							_parent.consoleFn.addTab('合同分包合同统计',2,url,null);
						}
					}
					break;
				default:
					break;
			}
		});
	});
</script>
</head>
<body  class="easyui-layout">
		<!-- 但行高度33px，多行时 33乘以行数  -->
		<div id="querybar" data-options="region:'north',split:false,border:false" style="height:33px;">
			<div class="easyui-panel" data-options="fit:true,border:false">
				<!-- 查询条件表单，根据配置进行替换  -->
				<form id="queryForm" >
				 <input type="hidden" name="className" value="com.fs.jzzn.pojo.Contract" />
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="contractNo" style="width:240px;" data-options="label:'合同编号:'" />
					<input type="hidden" name="contractNo_searchType" value="like" />
				 </div>
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="partA" style="width:240px;" data-options="label:'合同甲方:'" />
					<input type="hidden" name="partA_searchType" value="like" />
				 </div>
				 <div style="margin-top:5px;margin-left:10px;float:left;">
				  	<input class="easyui-textbox" name="partB" style="width:240px;" data-options="label:'合同乙方:'" />
					<input type="hidden" name="partB_searchType" value="like" />
				 </div>
				</form>
			</div>
		</div>  
	
		<!-- 工具栏按钮 -->
		<div id="toolbar" class="easyui-panel" style="padding:3px;"></div>
		
		<!-- 表格 -->
		<div region="center" border="false">
			<table id="dataGrid"></table>
		</div>
</body>
</html>